<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>报修服务评价</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary-color: #4361ee;
            --secondary-color: #3f37c9;
            --success-color: #4cc9f0;
            --light-bg: #f8f9fa;
        }

        body {
            background-color: var(--light-bg);
            font-family: 'PingFang SC', 'Microsoft YaHei', sans-serif;
        }

        .evaluation-container {
            max-width: 600px;
            margin: 40px auto;
            padding: 0 15px;
        }

        .evaluation-card {
            background: white;
            border-radius: 12px;
            padding: 30px;
            box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
            transition: transform 0.3s ease;
        }

        .evaluation-card:hover {
            transform: translateY(-5px);
        }

        .evaluation-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .evaluation-header h3 {
            color: var(--secondary-color);
            font-weight: 600;
            margin-bottom: 8px;
        }

        .evaluation-header p {
            color: #6c757d;
            font-size: 14px;
        }

        .rating-section {
            margin-bottom: 25px;
        }

        .section-title {
            font-size: 16px;
            color: #495057;
            margin-bottom: 15px;
            font-weight: 500;
        }

        .star-rating {
            display: flex;
            justify-content: center;
            margin-bottom: 10px;
        }

        .star {
            font-size: 32px;
            color: #ddd;
            cursor: pointer;
            transition: color 0.2s;
            margin: 0 5px;
        }

        .star:hover, .star.active {
            color: #ffc107;
        }

        .rating-hint {
            text-align: center;
            color: var(--primary-color);
            font-size: 14px;
            font-weight: 500;
        }

        .tag-container {
            display: flex;
            flex-wrap: wrap;
            gap: 10px;
            margin-top: 10px;
        }

        .tag {
            padding: 8px 15px;
            background: #f1f3f5;
            border-radius: 20px;
            font-size: 14px;
            color: #495057;
            cursor: pointer;
            transition: all 0.3s;
        }

        .tag:hover, .tag.active {
            background: var(--primary-color);
            color: white;
        }

        .comment-section {
            margin-top: 25px;
        }

        .comment-input {
            width: 100%;
            padding: 15px;
            border: 1px solid #e9ecef;
            border-radius: 8px;
            min-height: 120px;
            resize: none;
            transition: border 0.3s;
        }

        .comment-input:focus {
            outline: none;
            border-color: var(--primary-color);
            box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.2);
        }

        .word-count {
            text-align: right;
            font-size: 12px;
            color: #6c757d;
            margin-top: 5px;
        }

        .submit-btn {
            width: 100%;
            padding: 12px;
            background: var(--primary-color);
            color: white;
            border: none;
            border-radius: 8px;
            font-weight: 500;
            margin-top: 20px;
            transition: background 0.3s;
        }

        .submit-btn:hover {
            background: var(--secondary-color);
        }

        .repair-info {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 25px;
        }

        .info-item {
            display: flex;
            margin-bottom: 8px;
        }

        .info-label {
            width: 80px;
            color: #6c757d;
        }

        .info-value {
            color: #495057;
            font-weight: 500;
        }
    </style>
</head>
<body>
<div class="evaluation-container">
    <div class="evaluation-card">
        <div class="evaluation-header">
            <h3>报修服务评价</h3>
            <p>您的评价将帮助我们提供更好的服务</p>
        </div>

        <div class="repair-info" onclick="addEvaluation()">
            <div class="info-item">
                <span class="info-label">报修单号:</span>
                <span class="info-value"><%=request.getParameter("orderId")%></span>
            </div>
            <div class="info-item">
                <span class="info-label">报修项目:</span>
                <span class="info-value"><%=request.getParameter("description")%></span>
            </div>
            <div class="info-item">
                <span class="info-label">处理人员:</span>
                <span class="info-value">李师傅</span>
            </div>
            <div class="info-item">
                <span class="info-label">完成时间:</span>
                <span class="info-value"><%=request.getParameter("createdAt")%></span>
            </div>
        </div>

        <div class="rating-section">
            <div class="section-title">服务满意度</div>
            <div class="star-rating">
                <span class="star active" data-value="1"><i class="far fa-star"></i></span>
                <span class="star" data-value="2"><i class="far fa-star"></i></span>
                <span class="star" data-value="3"><i class="far fa-star"></i></span>
                <span class="star" data-value="4"><i class="far fa-star"></i></span>
                <span class="star" data-value="5"><i class="far fa-star"></i></span>
            </div>
            <div class="rating-hint"></div>
        </div>

        <div class="tag-section">
            <div class="section-title">服务亮点 (可多选)</div>
            <div class="tag-container">
                <span class="tag">响应迅速</span>
                <span class="tag active">维修专业</span>
                <span class="tag">态度友好</span>
                <span class="tag">解决问题彻底</span>
                <span class="tag">收费合理</span>
            </div>
        </div>

        <div class="comment-section">
            <div class="section-title">评价内容</div>
            <textarea class="comment-input" placeholder="请描述您的服务体验..."></textarea>
            <div class="word-count">0/200</div>
        </div>

        <button class="submit-btn">提交评价</button>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>

    function addEvaluation() {
        window.location.href = 'repair_list.jsp?orderId=<%=request.getParameter("orderId")%>&description=<%=request.getParameter("description")%>&createdAt=<%=request.getParameter("createdAt")%>';
    }

    // 在$(document).ready()中添加以下代码
    $(document).ready(function() {
        // 从URL获取参数并填充
        const urlParams = new URLSearchParams(window.location.search);
        const orderId = urlParams.get('orderId');
        const description = urlParams.get('description');
        const createdAt = urlParams.get('createdAt');
        
        if(orderId) {
            $('.info-value:eq(0)').text(orderId);
        }
        if(description) {
            $('.info-value:eq(1)').text(decodeURIComponent(description));
        }
        if(createdAt) {
            $('.info-value:eq(3)').text(decodeURIComponent(createdAt));
        }
        
        // 星级评分交互
        $('.star').click(function() {
            const value = $(this).data('value');
            $('.star').removeClass('active');
            $('.star').each(function() {
                if ($(this).data('value') <= value) {
                    $(this).addClass('active');
                    $(this).html('<i class="fas fa-star"></i>');
                } else {
                    $(this).html('<i class="far fa-star"></i>');
                }
            });

            // 更新评分提示
            const ratings = ['非常差', '差', '一般', '满意', '非常满意'];
            $('.rating-hint').text(value + '.0分 ' + ratings[value-1]);
        });

        // 标签选择交互
        $('.tag').click(function() {
            $(this).toggleClass('active');
        });

        // 字数统计
        $('.comment-input').on('input', function() {
            const count = $(this).val().length;
            $('.word-count').text(count + '/200');
        });
         // 提交评价
        $('.submit-btn').click(function() {
            // 获取评价数据
            const rating = $('.star.active').last().data('value') || 0;
            const content = $('.comment-input').val();
            const tags = [];
            $('.tag.active').each(function() {
                tags.push($(this).text());
            });
            
            // 获取报修单信息
            const orderId = $('.info-value:eq(0)').text();
            
            // 验证数据
            if (rating === 0) {
                alert('请选择评分');
                return;
            }
            if (content.trim() === '') {
                alert('请输入评价内容');
                return;
            }
            const description = $('.info-value:eq(1)').text(); // 获取报修项目作
            // 发送数据到后端
            $.post('<%=request.getContextPath()%>/evaluationController', {
                op: 'add',
                orderId: orderId,
                description: description, // 添加description字段
                rating: rating,
                content: content,
                tags: tags.join(','),
                nickname: '当前用户昵称' // 这里需要获取当前登录用户的昵称

            }, function(response) {
                if (response.success) {
                    alert('评价提交成功！');
                    window.location.href = 'repair_evaluationList.jsp';
                } else {
                    alert('提交失败: ' + response.message);
                }
            }, 'json').fail(function() {
                alert('网络错误，请稍后重试');
            });
        });
    });
</script>
</body>
</html>